/*Title: Home Security System.

Hardware Used: Aurdino uno,3 IR Sensors.

Description: This will provide security to the home from thieves,unwanted people.

auothers: NAVEEN KUMAR GUPTA*/
          
#define SEN1 2
//Sensor 1 has defined on pin 2//
#define SEN2 3
//Sensor 2 has defined on pin 3//
int val1,val2,i,hist[20],sum,avg;

void setup()//This is the function in which the code runs only one time//
{
  Serial.begin(9600);
  //Used for UART communication to make the baud rate equal//
  pinMode(SEN1,INPUT);
  //Input has taken from sensor1//
  pinMode(SEN2,INPUT);
  //Input has taken from sensor2//
}
void loop()//This is the function in which the code runs infinite times//
{
 chk_window();
 //User defined fuction named chk_window is calling in loop function//
 chk_collidor();
 //User defined fuction named chk_collidor is calling in loop function//
 get input();
 //User defined fuction named get input is calling in loop function//
}
void chk_window()//This function is made for checking window//
{
  val1=digitalRead(SEN1);
  //This will read the value of sensor 1//
  val2=digitalRead(SEN2);
  //This will read the value of sensor 2//
  Serial.println(val1);
  //This will print the value of sensor 1//
  Serial.println(val2);
  //This will print the value of sensor 2//
  if(val1==1&&val2==1)//It will compare the value of sensor 1 & sensor 2//
  {
    Serial.print("SAFE");
    //It will print "SAFE" if the above condition is true//
  }
  if((val1==1&&val2==0)||(val1==0&&val2==1))//It will also compare the value of sensor 1 & sensor 2//
  {
    Serial.print("ALARM");
    //It will print "ALARM" if the above condition is true//
  }
  if(val1==0&&val2==0)//It will also compare the value of sensor 1 & sensor 2//
  {
    Serial.print("WARNING");
    //It will print "WARNING" if the above condition is true//
  }
}
void chk_collidor()//This function is made for checking collidor//
{
  for(i=0;i<20;i++)//Here for loop is used to take the 20 values of analog sensor//
  {
    hist[i]=analogRead(A0);
    //Here the 20 values of analog sensor is storing in variable hist[20] at the delay of 100 milliseconds//
    delay(100);
    //The delay of 100 milliseconds is provided here//
  }
  for(i=0;i<19;i++)//Here for loop is used to fetch the 20 values of variable hist[20]//
  {
    sum=(hist[i+1]-hist[i]);
    //Here the difference of two consecutive values of variable hist[20] gets saving in the variable sum//
  }
  if(sum<0)//It will compare the value of sum//
  {
   mode_safe();
   //It will call the function mode_safe if the above condition is true//
  }
  else if((sum>0)&&(sum<1000))//It will also compare the value of sum// 
  {
   mode_warning(); 
   //It will call the function mode_warning if the above condition is true//
  }
  else
  {
    mode_alert();
    //Otherwise it will call mode alert// 
  }
}
 void mode_safe()//This is the function made for safe condition//
{
   Serial.print("SAFE");
   //It will print "SAFE"//
} 
 void mode_warning()//This is the function made to give warning//
 {
   Serial.print("WARNING");
   //It will print "WARNING"//
 }
 void mode_alert()//This is the function made to alert the user// 
 {
   avg=sum/20;
   //It will calculate the average of sum//
   if(avg>1000)//It will compare the value of avg//
   {
   Serial.print("ALERT");
   //It will print "ALERT"//
   
 }
 void get input()//This is the function made to take input from user//
 {
   Serial.read(alarm 1)
   Serial.read(alarm 2)
 }
 
